package com.example.fashionshoes.service.coupon;

import com.example.fashionshoes.exception.BusinessException;
import com.example.fashionshoes.pojo.po.Coupon;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * 折扣优惠劵
 */
public class DiscountCoupon implements CouponStrategy {
    @Override
    public BigDecimal useCoupon(BigDecimal price, Coupon coupon) throws BusinessException {
        DecimalFormat decimalFormat =new DecimalFormat("#.00");
        String discount = coupon.getDiscount();
        if (Double.parseDouble(coupon.getDiscount()) > 100) {
            throw new BusinessException("折扣力度不合理！");
        }
        return new BigDecimal(decimalFormat.format(price.multiply(new BigDecimal(discount).movePointLeft(2))));
        //0全场通用,1指定分类,2指定商品
    }
}
